<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>dropper</title>
    <style>
        .box {
            width: 200px;
            height: 200px;
            border: 1px solid #ccc;
        }
    </style>
</head>

<body>
    <button>取色</button>
    <label></label>
    <div class="box"></div>
    <script>
        const btn = document.querySelector('button');
        const box = document.querySelector('.box');
        const label = document.querySelector('label');
        btn.onclick = async () => {
            const dropper = new EyeDropper();
            try {
                const result = await dropper.open();
                console.log(result)
                box.style.backgroundColor = label.textContent = result.sRGBHex;
            } catch (error) {
                console.log('user canceled');
            }
        }
    </script>
</body>

</html>